package com.java.module.chat.controller.admin;

import java.util.List;

import com.java.module.chat.domain.DisableWord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.domain.page.TableDataInfo;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.common.utils.poi.ExcelUtil;
import com.java.module.chat.service.IDisableWordService;

/**
 * 聊天：禁用词Controller
 * 
 * @author Administrator
 * @date 2021-05-13
 */
@RestController("AdminDisableWordController")
@RequestMapping("/chat/word")
public class DisableWordController {

    @Autowired
    private IDisableWordService disableWordService;

    /**
     * 查询聊天：禁用词列表
     */
    @PreAuthorize("@ss.hasPermi('chat:word:list')")
    @GetMapping("/list")
    public TableDataInfo list(DisableWord disableWord) {
        WebKit.startPage();
        List<DisableWord> list = disableWordService.selectDisableWordList(disableWord);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出聊天：禁用词列表
     */
    @PreAuthorize("@ss.hasPermi('chat:word:export')")
    @Log(title = "聊天：禁用词", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DisableWord disableWord) {
        List<DisableWord> list = disableWordService.selectDisableWordList(disableWord);
        ExcelUtil<DisableWord> util = new ExcelUtil<DisableWord>(DisableWord.class);
        return util.exportExcel(list, "word");
    }

    /**
     * 获取聊天：禁用词详细信息
     */
    @PreAuthorize("@ss.hasPermi('chat:word:query')")
    @GetMapping(value = "/{wid}")
    public AjaxResult getInfo(@PathVariable("wid") Long wid) {
        return AjaxResult.success(disableWordService.selectDisableWordById(wid));
    }

    /**
     * 新增聊天：禁用词
     */
    @PreAuthorize("@ss.hasPermi('chat:word:add')")
    @Log(title = "聊天：禁用词", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DisableWord disableWord) {
        return WebKit.toAjax(disableWordService.insertDisableWord(disableWord));
    }

    /**
     * 修改聊天：禁用词
     */
    @PreAuthorize("@ss.hasPermi('chat:word:edit')")
    @Log(title = "聊天：禁用词", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DisableWord disableWord) {
        return WebKit.toAjax(disableWordService.updateDisableWord(disableWord));
    }

    /**
     * 删除聊天：禁用词
     */
    @PreAuthorize("@ss.hasPermi('chat:word:remove')")
    @Log(title = "聊天：禁用词", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{wids}")
    public AjaxResult remove(@PathVariable Long[] wids) {
        return WebKit.toAjax(disableWordService.deleteDisableWordByIds(wids));
    }

}